package com.ruoyi.sso.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sso.domain.SsoUserWyUrl;
import com.ruoyi.sso.domain.SystemSsoUserWyUrl;
import com.ruoyi.sso.service.ISsoUserWyUrlService;

/**
 * 系统用户与物管关联Controller
 * 
 * @author zsj
 * @date 2020-01-08
 */
@Controller
@RequestMapping("/sso/userWyUrl")
public class SsoUserWyUrlController extends BaseController
{
    private String prefix = "sso/userWyUrl";

    @Autowired
    private ISsoUserWyUrlService ssoUserWyUrlService;

    @RequiresPermissions("sso:userWyUrl:view")
    @GetMapping()
    public String userWyUrl()
    {
        return prefix + "/userWyUrl";
    }

    /**
     * 查询系统用户与物管关联列表
     */
    @RequiresPermissions("sso:userWyUrl:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SsoUserWyUrl ssoUserWyUrl)
    {
        startPage();
        List<SsoUserWyUrl> list = ssoUserWyUrlService.selectSsoUserWyUrlList(ssoUserWyUrl);
        return getDataTable(list);
    }

    /**
     * 导出系统用户与物管关联列表
     */
    @RequiresPermissions("sso:userWyUrl:export")
    @Log(title = "系统用户与物管关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SsoUserWyUrl ssoUserWyUrl)
    {
        List<SsoUserWyUrl> list = ssoUserWyUrlService.selectSsoUserWyUrlList(ssoUserWyUrl);
        ExcelUtil<SsoUserWyUrl> util = new ExcelUtil<SsoUserWyUrl>(SsoUserWyUrl.class);
        return util.exportExcel(list, "userWyUrl");
    }

    /**
     * 新增系统用户与物管关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存系统用户与物管关联
     */
    @RequiresPermissions("sso:userWyUrl:add")
    @Log(title = "系统用户与物管关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SsoUserWyUrl ssoUserWyUrl)
    {
        return toAjax(ssoUserWyUrlService.insertSsoUserWyUrl(ssoUserWyUrl));
    }

    /**
     * 修改系统用户与物管关联
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SsoUserWyUrl ssoUserWyUrl = ssoUserWyUrlService.selectSsoUserWyUrlById(id);
        mmap.put("ssoUserWyUrl", ssoUserWyUrl);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统用户与物管关联
     */
    @RequiresPermissions("sso:userWyUrl:edit")
    @Log(title = "系统用户与物管关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SsoUserWyUrl ssoUserWyUrl)
    {
        return toAjax(ssoUserWyUrlService.updateSsoUserWyUrl(ssoUserWyUrl));
    }

    /**
     * 删除系统用户与物管关联
     */
    @RequiresPermissions("sso:userWyUrl:remove")
    @Log(title = "系统用户与物管关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ssoUserWyUrlService.deleteSsoUserWyUrlByIds(ids));
    }
}
